<template>
	<view class="content">
		<view :style="{background: `url(${images.bg})`, backgroundRepeat: 'no-repeat', paddingBottom: '480rpx', backgroundSize:'140%'}">
			<u-navbar :is-back="true" :background="background" back-icon-color="#fff" :border-bottom="false" :is-fixed="false">
				<view class="slot-wrap" style="color: #fff; font-size: 32rpx;width: 530rpx;">
					<view class="slot-wrap" style="color: #fff; font-size: 32rpx;width: 530rpx;">
						<view style="display: flex;justify-content: center;width: 100%;">
							会员中心
						</view>
					</view>
				</view>
			</u-navbar>
		</view>
		
		<view style="display: flex;justify-content: center;margin-top: -448rpx;">
			<view
				:style="{background: `url(${images.pg})`, backgroundRepeat: 'no-repeat', width: '710rpx', height: '360rpx', backgroundSize: '100%'}">
				
				<view style="display: flex;flex-direction: row;padding: 44rpx 40rpx;align-items: center;justify-content: space-between;">
					<view style="display: flex;align-items: center;justify-content: center;flex-direction: column;position: relative;">
						<u-avatar :src="user.avatar" size="160"></u-avatar>
						<view v-if="user.is_vip == 1" style="width: 40rpx;height: 40rpx;position: absolute;bottom: 20rpx;right: 0;">
							<u-image width="40rpx" height="40rpx" src="https://img.koalalf.com/center/s-vip.png" mode="widthFix"></u-image>
						</view>
					</view>
					<view style="display: flex;flex-direction: column; color: #805033;margin-left: 20rpx;flex: 1;">
						<text style="font-size: 48rpx;color: #805033;font-weight: bold;">{{user.nick_name}}</text>
						<text v-if="user.is_vip == 1" style="margin-top: 20rpx;">{{user.vip_expiration_date}}到期</text>
					</view>
					<button v-if="user.is_vip == 0" @click="userUpgradeVip()" :plain="true" style="border: none;background-color: #DCA170; border-radius: 31rpx;height: 62rpx;line-height: 52rpx;" >
						<text style="color: #fff;font-size: 26rpx;">立即开通</text>
					</button>
					<button v-if="user.is_vip == 1" @click="userUpgradeVip()" :plain="true" style="border: none;background-color: #DCA170; border-radius: 31rpx;height: 62rpx;line-height: 52rpx;" >
						<text style="color: #fff;font-size: 26rpx;">立即续费</text>
					</button>
				</view>
				<view v-if="user.is_vip == 1" style="font-size: 56rpx;color: #B87545;font-weight: bold;text-align: center;">{{user.vip_number}}</view>
				<view v-if="user.is_vip == 0" style="font-size: 56rpx;color: #B87545;font-weight: bold;text-align: center;">**** **** **** ****</view>
			</view>
		</view>
		
		<view style="background-color: #fff;margin: 32rpx;border-radius: 20rpx;padding: 40rpx;">
			<view style="display: flex;justify-content: center;">
				<view style="position: relative;width: 240rpx;">
					<view style="color: #87593C; font-size: 40rpx;position: relative;top: 0;z-index: 1;">会员尊享权益</view>
					<view style="background-color: #F1D6C6;width: 204rpx; height: 16rpx;position: absolute;border-radius: 8rpx;bottom: 0;left: 18rpx;"></view>
				</view>
			</view>
			<view style="display: flex;flex-direction: row;justify-content: space-between;margin-top: 40rpx;">
				<view style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
					<u-image width="100rpx" src="https://img.koalalf.com/vip/1%402x.png" mode="widthFix"></u-image>
					<view style="color: #666;font-size: 28rpx;margin-top: 10rpx;">专属价格</view>
				</view>
				<view style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
					<u-image width="100rpx" src="https://img.koalalf.com/vip/2%402x.png" mode="widthFix"></u-image>
					<view style="color: #666;font-size: 28rpx;margin-top: 10rpx;">专属产品</view>
				</view>
				<view style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
					<u-image width="100rpx" src="https://img.koalalf.com/vip/3%402x.png" mode="widthFix"></u-image>
					<view style="color: #666;font-size: 28rpx;margin-top: 10rpx;">专属活动</view>
				</view>
			</view>
		</view>
		
		<view style="background-color: #fff;margin: 32rpx;border-radius: 20rpx;padding: 40rpx;">
			<view style="display: flex;justify-content: center;">
				<view style="position: relative;width: 160rpx;">
					<view style="color: #87593C; font-size: 40rpx;position: relative;top: 0;z-index: 1;">持卡须知</view>
					<view style="background-color: #F1D6C6;width: 120rpx; height: 16rpx;position: absolute;border-radius: 8rpx;bottom: 0;left: 18rpx;"></view>
				</view>
			</view>
			<view style="display: flex;flex-direction: column;justify-content: space-between;margin-top: 40rpx;">
                <view style="color: #333;font-size: 28rpx;display: flex;flex-direction: row;padding: 10rpx 0;">
					<text>1、</text><text>持本卡者可享受折优惠或抵扣多少元现金。抵扣多少元现金</text>
				</view>
				<view style="color: #333;font-size: 28rpx;display: flex;flex-direction: row;padding: 10rpx 0;">
					<text>2、</text><text>持本卡者可享受折优惠或抵扣多少元现金。抵扣多少元现金</text>
				</view>
				<view style="color: #333;font-size: 28rpx;display: flex;flex-direction: row;padding: 10rpx 0;">
					<text>3、</text><text>本卡最终解释权归平台所有。</text>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import imagesUrl from '../../common/images.js'
	export default {
		data() {
			return {
				images: {},
				background: {
					// background: "url('/static/my/bg@2x.png') no-repeat",
					backgroundSize: "100%",
					width: '100vw'
				},
				user: null
			}
		},
		onLoad() {
			let that = this;
			this.$u.api.userInfoByToken({}).then(res => {
				that.user = res
				uni.setStorageSync('user_info', JSON.stringify(res))
			})
			this.images = imagesUrl.vip
		},
		methods: {
			userUpgradeVip(){
				let that = this;
				this.$u.api.userUpgradeVip({}).then(res => {
					uni.requestPayment({
						provider: 'wxpay',
						orderInfo: 'order_id:'+ "userUpgradeVip"+that.user.id,
						timeStamp: res.timestamp,
						nonceStr: res.nonceStr,
						package: res.package,
						signType: res.signType,
						paySign: res.paySign,
						success: function(res) {
							that.$u.route({
								url: '/pages/rechange/paySuccess'
							})
						},
						fail: function(err) {
							that.$api.msg("支付失败"+err);
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		min-height: 100vh;
		background-color: #f5f5f5;
	}
</style>
